/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLyThuoc;

import GiaoDien.GiaoDienChinh;
import KetNoiSQL.KetNoiSQL;
import KiemTra.KiemTra;
import QuanLyDonViTinh.DonViTinh;
import QuanLyLoaiThuoc.LoaiThuoc;
import QuanLyNhaCungCap.NhaCungCap;
import java.awt.event.ItemEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;

/**
 *
 * @author PhuongNga
 */
public class CapNhat extends javax.swing.JFrame {

    Vector vLay = new Vector();
    DefaultComboBoxModel modelLoaiThuoc = new DefaultComboBoxModel();
    DefaultComboBoxModel modelNhaCungCap = new DefaultComboBoxModel();
    DanhSachThuoc dst = new DanhSachThuoc();
    LoaiThuoc lt = new LoaiThuoc();
    NhaCungCap ncc = new NhaCungCap();
    Thuoc t, t1 = new Thuoc();
    DonViTinh dvt = new DonViTinh();
    KiemTra ktCTT = new KiemTra();

    public CapNhat() {
        try {
            setResizable(false);
            initComponents();
            vLay = NhaCungCap.layTenNhaCungCap();
            layTenNhaCungCap(vLay);

            vLay = LoaiThuoc.xemTenLoaiThuoc();
            layTenLoaiThuoc(vLay);

            vLay = Thuoc.xemThuoc();
            layTenThuoc(vLay);
            layTenChonThuoc(vLay);

            vLay = DonViTinh.xemDonViTinh();
            layDonViTinh(vLay);
        } catch (SQLException ex) {
            Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //Lấy tên Loại thuốc
    public void layTenLoaiThuoc(Vector vLay) {
        Vector loaiThuoc = new Vector();
        loaiThuoc.addElement("---Chọn loại thuốc---");
        for (int i = 0; i < vLay.size(); i++) {
            lt = (LoaiThuoc) vLay.get(i);
            loaiThuoc.addElement(lt.getTenLoaiThuoc());
        }
        DefaultComboBoxModel modelLoaiThuoc = new DefaultComboBoxModel(loaiThuoc);
        cbLoaiThuoc.setModel(modelLoaiThuoc);
    }

    //Lấy tên nhà cung cấp
    public void layTenNhaCungCap(Vector vLay) {
        Vector nhaCungCap = new Vector();
        nhaCungCap.addElement("---Chọn Nhà cung cấp---");
        for (int i = 0; i < vLay.size(); i++) {
            ncc = (NhaCungCap) vLay.get(i);
            nhaCungCap.addElement(ncc.getTenNhaCungCap());
        }
        DefaultComboBoxModel modelNCC = new DefaultComboBoxModel(nhaCungCap);
        cbNhaCungCap.setModel(modelNCC);
    }
    //Lấy tên thuốc vào combobox chi tiết thuốc

    public void layTenThuoc(Vector vLay) {
        Vector Thuoc = new Vector();
        Thuoc.addElement("---Chọn tên Thuốc---");
        for (int i = 0; i < vLay.size(); i++) {
            t = (Thuoc) vLay.get(i);
            Thuoc.addElement(t.getTenThuoc());
        }
        DefaultComboBoxModel modelThuoc = new DefaultComboBoxModel(Thuoc);
        cbTenThuoc.setModel(modelThuoc);
    }
    //Lấy tên thuốc vào bảng thuốc
    public void layTenChonThuoc(Vector vLay) {
        Vector Thuoc = new Vector();
        Thuoc.addElement("---Chọn tên Thuốc---");
        for (int i = 0; i < vLay.size(); i++) {
            t = (Thuoc) vLay.get(i);
            Thuoc.addElement(t.getTenThuoc());
        }
        DefaultComboBoxModel modelThuoc = new DefaultComboBoxModel(Thuoc);
        cbChonTenThuoc.setModel(modelThuoc);
    }

    //Lấy đơn vị tính
    public void layDonViTinh(Vector vLay) {
        Vector donViTinh = new Vector();
        donViTinh.addElement("---Chọn Đơn vị tính---");
        for (int i = 0; i < vLay.size(); i++) {
            dvt = (DonViTinh) vLay.get(i);
            donViTinh.addElement(dvt.getTenDonViTinh());
        }
        DefaultComboBoxModel modeldvt = new DefaultComboBoxModel(donViTinh);
        cbTenDonViTinh.setModel(modeldvt);
    }

    //Kiểm tra tên thuốc có trùng hay không
    public boolean kiemTraTenThuoc() {
        boolean kt = true;
        int dem = 0;

        Vector thuoc = new Vector();
        try {
            thuoc = Thuoc.xemThuoc();
        } catch (SQLException ex) {
            Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < thuoc.size(); i++) {
            t = (Thuoc) thuoc.get(i);
            if (txtTenThuoc.getText().toString().equals(t.getTenThuoc().toString())) {
                dem++;
            }
        }
        if (dem != 0) {
            int show = JOptionPane.showConfirmDialog(this, "Tên thuốc bạn vừa nhập  bị trùng " + dem + " giá trị.Bạn vẫn muốn lưu?", "Thông báo", JOptionPane.YES_NO_OPTION);
            if (show == JOptionPane.YES_OPTION) {
                kt = true;
            }
            if (show == JOptionPane.NO_OPTION) {
                kt = false;
            }
        }
        return kt;
    }
    //Phương thức cập nhật thuốc-------------------------------------------------------------------

    public void capNhatThuoc() {

        if (cbChonTenThuoc.getSelectedItem().toString().equals("---Chọn tên Thuốc---")) {
            JOptionPane.showMessageDialog(null, "Bạn chưa chọn tên thuốc để thay đổi");
            cbChonTenThuoc.requestFocus();
            return;
        } else if (txtTenThuoc.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Bạn chưa nhập tên thuốc mới", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
            txtTenThuoc.requestFocus();
            return;
        } else if (cbLoaiThuoc.getSelectedItem().toString().equals("---Chọn loại thuốc---")) {
            JOptionPane.showMessageDialog(null, "Bạn chưa chọn loại thuốc");
            cbLoaiThuoc.requestFocus();
            return;
        } else if (cbNhaCungCap.getSelectedItem().toString().equals("---Chọn Nhà cung cấp---")) {
            JOptionPane.showMessageDialog(null, "Bạn chưa chọn nhà cung cấp");
            cbNhaCungCap.requestFocus();
            return;
        } else if (kiemTraTenThuoc() == false) {
            txtTenThuoc.setText("");
            return;
        }
        int kt = 0;

        //Đổi tên thuốc thành mã thuốc
        Vector vThuoc = new Vector();
        try {
            vThuoc = Thuoc.xemThuoc();
        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < vThuoc.size(); i++) {
            t1 = (Thuoc) vThuoc.get(i);
            if (cbTenThuoc.getSelectedItem().toString().equals(t1.getTenThuoc().toString())) {
                t.setMaThuoc((int) t1.getMaThuoc());
            }
        }
        t.setTenThuoc(txtTenThuoc.getText().trim());
        //Đổi tên loại thuốc thành mã loại thuốc
        Vector vLoaiThuoc = new Vector();
        try {
            vLoaiThuoc = LoaiThuoc.xemLoaiThuoc();
        } catch (SQLException ex) {
            Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < vLoaiThuoc.size(); i++) {
            lt = (LoaiThuoc) vLoaiThuoc.get(i);
            //so sánh tên trùng thì lấy ra mã loại thuốc
            if (cbLoaiThuoc.getSelectedItem().toString().equals(lt.getTenLoaiThuoc().toString())) {
                t.setMaLoaiThuoc((int) lt.getMaLoaiThuoc());
            }
        }
        //Đổi tên nhà cung cấp thành mã nhà cung cấp
        Vector vNhaCungCap = new Vector();
        try {
            vNhaCungCap = NhaCungCap.xemNhaCungCap();
        } catch (SQLException ex) {
            Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < vNhaCungCap.size(); i++) {
            ncc = (NhaCungCap) vNhaCungCap.get(i);
            if (cbNhaCungCap.getSelectedItem().toString().equals(ncc.getTenNhaCungCap().toString())) {
                t.setMaNhaCungCap((int) ncc.getMaNhaCungCap());
            }
        }
        try {
            kt = Thuoc.capNhatThuoc(t);
            if (kt == 1) {
                JOptionPane.showMessageDialog(this, "Cập nhật thành công!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                try {
                    vLay = Thuoc.xemThuoc();//Hiển thị lên from chi tiết thuốc
                    layTenThuoc(vLay);
                    layTenChonThuoc(vLay);
                    huy();
                } catch (SQLException ex) {
                    Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
                }

            } else {
                JOptionPane.showMessageDialog(this, "Cập nhật không thành công.Bạn hãy xem lại", "Thông báo", JOptionPane.ERROR_MESSAGE);
            }
        } catch (SQLException ex) {
            Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //Kiểm tra chi tiết thuốc
    public boolean ktraCTT() {
        boolean ktctt = true;
        if (cbTenThuoc.getSelectedItem().toString().equals("---Chọn tên Thuốc---")) {
            JOptionPane.showMessageDialog(null, "Bạn chưa chọn tên thuốc");
            cbTenThuoc.requestFocus();
            ktctt = false;
        } else if (cbTenDonViTinh.getSelectedItem().toString().equals("---Chọn Đơn vị tính---")) {
            JOptionPane.showMessageDialog(null, "Bạn chưa chọn Đơn vị tính");
            cbTenDonViTinh.requestFocus();
            ktctt = false;
        } else if (!ktCTT.kiemTraSo(txtGia.getText().trim())) {
            JOptionPane.showMessageDialog(null, "Giá bạn nhập chưa đúng.Nhập lại");
            txtGia.setText("");
            txtGia.requestFocus();
            ktctt = false;
        } else if (!ktCTT.kiemTraSo(txtSoLuong.getText().trim())) {
            JOptionPane.showMessageDialog(null, "Số lượng bạn nhập chưa đúng.Nhập lại");
            txtSoLuong.setText("");
            txtSoLuong.requestFocus();
            ktctt = false;
        } else if (txtNam.equals("")) {
            txtNam.setText("0");
        } else if (!ktCTT.kiemTraNam(txtNam.getText().trim())) {
            JOptionPane.showMessageDialog(null, "Năm bạn nhập chưa đúng.Nhập lại");
            txtNam.setText("");
            txtNam.requestFocus();
            ktctt = false;
        }

        return ktctt;

    }

    //Thêm bảng chi tiết thuốc
    public void capNhatChiTietThuoc() {
        if (!ktraCTT()) {
            return;
        }
        int kt = 0;
        //Đổi tên thuốc thành mã thuốc
        Vector vThuoc = new Vector();
        try {
            vThuoc = Thuoc.xemThuoc();
        } catch (SQLException ex) {
            Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < vThuoc.size(); i++) {
            t1 = (Thuoc) vThuoc.get(i);
            if (cbTenThuoc.getSelectedItem().toString().equals(t1.getTenThuoc().toString())) {
                t.setMaThuoc((int) t1.getMaThuoc());
            }
        }
        //Đổi đơn vị tinh
        Vector vDonViTinh = new Vector();
        try {
            vDonViTinh = DonViTinh.xemDonViTinh();
        } catch (SQLException ex) {
            Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < vDonViTinh.size(); i++) {
            dvt = (DonViTinh) vDonViTinh.get(i);
            if (cbTenDonViTinh.getSelectedItem().toString().equals(dvt.getTenDonViTinh().toString())) {
                t.setMaDonViTinh(dvt.getMaDonViTinh().trim());
            }
        }
        float gia = Float.parseFloat(txtGia.getText().trim());
        t.setGia(gia);
        int soLuong = Integer.parseInt(txtSoLuong.getText().trim());
        t.setSoLuong(soLuong);
        t.setNguonGoc(txtNguonGoc.getText().trim());
        t.setCongDung(txtCongDung.getText().trim());
        //Lấy hạn sử dụng
        String hsd;
        hsd = (String) cbNgay.getSelectedItem() + "/" + cbThang.getSelectedItem() + "/" + txtNam.getText().trim();
        t.setHanDung(hsd);
        t.setHuongDanDung(txtHuongDanDung.getText().trim());

        try {
            kt = Thuoc.capNhatChiTietThuoc(t);
            if (kt == 1) {
                JOptionPane.showMessageDialog(this, "Cập nhật thuốc thành công!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                huyctt();
            } else {
                JOptionPane.showMessageDialog(this, "Cập nhật không thành công.Bạn hãy xem lại", "Thông báo", JOptionPane.ERROR_MESSAGE);
            }
        } catch (SQLException ex) {
            Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //Hủy bảng thuốc
    public void huy() {
        try {
            txtTenThuoc.setText("");
            vLay = NhaCungCap.layTenNhaCungCap();
            layTenNhaCungCap(vLay);
            vLay = LoaiThuoc.xemTenLoaiThuoc();
            layTenLoaiThuoc(vLay);
            txtTenThuoc.requestFocus();
        } catch (SQLException ex) {
            Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //hủy bảng chi tiết thuốc

    public void huyctt() {
        try {
            vLay = Thuoc.xemThuoc();
            layTenThuoc(vLay);
            vLay = DonViTinh.xemDonViTinh();
            layDonViTinh(vLay);
            txtGia.setText("");
            txtSoLuong.setText("");
            txtHuongDanDung.setText("");
            txtCongDung.setText("");
            txtNguonGoc.setText("");
            txtNam.setText("");
            cbNgay.setSelectedItem("1");
            cbThang.setSelectedItem("1");
            cbTenThuoc.requestFocus();

        } catch (SQLException ex) {
            Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDateChooserBeanInfo1 = new com.toedter.calendar.JDateChooserBeanInfo();
        jDateChooserBeanInfo2 = new com.toedter.calendar.JDateChooserBeanInfo();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        cbTenThuoc = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        cbTenDonViTinh = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        txtGia = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtSoLuong = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        txtNguonGoc = new javax.swing.JTextField();
        txtCongDung = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtHuongDanDung = new javax.swing.JTextArea();
        btCapNhatCTT = new javax.swing.JButton();
        btDongDS = new javax.swing.JButton();
        btHuyDS = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        cbNgay = new javax.swing.JComboBox();
        cbThang = new javax.swing.JComboBox();
        txtNam = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cbLoaiThuoc = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        cbNhaCungCap = new javax.swing.JComboBox();
        btCapNhat = new javax.swing.JButton();
        btHuy = new javax.swing.JButton();
        btDong = new javax.swing.JButton();
        cbChonTenThuoc = new javax.swing.JComboBox();
        txtTenThuoc = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel5.setText("Tên thuốc");

        cbTenThuoc.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbTenThuoc.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbTenThuocItemStateChanged(evt);
            }
        });
        cbTenThuoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTenThuocActionPerformed(evt);
            }
        });

        jLabel6.setText("Tên đơn vị tính");

        cbTenDonViTinh.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel7.setText("Giá");

        txtGia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtGiaActionPerformed(evt);
            }
        });

        jLabel1.setText("Số lượng");

        jLabel8.setText("Nguồn gốc");

        jLabel9.setText("Công dụng");

        jLabel11.setText("Hạn dùng");

        jLabel12.setText("Hướng dẫn dùng");

        txtNguonGoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNguonGocActionPerformed(evt);
            }
        });

        txtCongDung.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCongDungActionPerformed(evt);
            }
        });

        txtHuongDanDung.setColumns(20);
        txtHuongDanDung.setRows(5);
        jScrollPane1.setViewportView(txtHuongDanDung);

        btCapNhatCTT.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/add 1.png"))); // NOI18N
        btCapNhatCTT.setText("Cập nhật");
        btCapNhatCTT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCapNhatCTTActionPerformed(evt);
            }
        });

        btDongDS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Remove.png"))); // NOI18N
        btDongDS.setText("Đóng");
        btDongDS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDongDSActionPerformed(evt);
            }
        });

        btHuyDS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/cross.png"))); // NOI18N
        btHuyDS.setText("Hủy");
        btHuyDS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btHuyDSActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 36, Short.MAX_VALUE)
        );

        cbNgay.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        cbThang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(26, 26, 26)
                                .addComponent(cbTenThuoc, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtGia, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(18, 18, 18))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE)
                                        .addGap(37, 37, 37)))
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtNguonGoc, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(cbNgay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cbThang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(txtNam))))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(txtCongDung, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(17, 17, 17)
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(37, 37, 37)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtSoLuong, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(cbTenDonViTinh, javax.swing.GroupLayout.Alignment.LEADING, 0, 178, Short.MAX_VALUE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(btCapNhatCTT)
                        .addGap(34, 34, 34)
                        .addComponent(btHuyDS, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(49, 49, 49)
                        .addComponent(btDongDS, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                        .addGap(228, 228, 228)))
                .addGap(23, 23, 23))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbTenThuoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(cbTenDonViTinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtGia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtSoLuong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNguonGoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(39, 39, 39)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbNgay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbThang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNam, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtCongDung, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(72, 72, 72)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(66, 66, 66)))))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btCapNhatCTT, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btHuyDS, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btDongDS, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Bảng chi tiết thuốc", jPanel2);

        jLabel2.setText("Tên thuốc mới");

        jLabel3.setText("Loại thuốc");

        jLabel4.setText("Nhà cung cấp");

        cbNhaCungCap.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btCapNhat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/add 1.png"))); // NOI18N
        btCapNhat.setText("Cập nhật");
        btCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCapNhatActionPerformed(evt);
            }
        });

        btHuy.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/cross.png"))); // NOI18N
        btHuy.setText("Hủy");
        btHuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btHuyActionPerformed(evt);
            }
        });

        btDong.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/exit.png"))); // NOI18N
        btDong.setText("Đóng");
        btDong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDongActionPerformed(evt);
            }
        });

        cbChonTenThuoc.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbChonTenThuoc.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbChonTenThuocItemStateChanged(evt);
            }
        });

        jLabel10.setText("Chọn tên thuốc");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addComponent(btCapNhat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(btHuy, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btDong, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(235, 235, 235))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(cbChonTenThuoc, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(36, 36, 36)
                            .addComponent(cbNhaCungCap, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txtTenThuoc)
                                .addComponent(cbLoaiThuoc, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(335, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbChonTenThuoc, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTenThuoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbLoaiThuoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(49, 49, 49)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbNhaCungCap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(57, 57, 57)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btCapNhat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btDong)
                    .addComponent(btHuy, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(80, 80, 80))
        );

        jTabbedPane1.addTab("Bảng thuốc", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addGap(19, 19, 19))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtGiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtGiaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtGiaActionPerformed

    private void txtNguonGocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNguonGocActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNguonGocActionPerformed

    private void txtCongDungActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCongDungActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCongDungActionPerformed

    private void cbTenThuocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTenThuocActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbTenThuocActionPerformed

    private void btCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCapNhatActionPerformed
        this.capNhatThuoc();

    }//GEN-LAST:event_btCapNhatActionPerformed

    private void btHuyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btHuyActionPerformed
        this.huy();
    }//GEN-LAST:event_btHuyActionPerformed

    private void btDongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDongActionPerformed
        int thongBao = JOptionPane.showConfirmDialog(null, "Bạn có muốn đóng cập nhật Thuốc?", "Thông báo", JOptionPane.YES_NO_OPTION);
        if (thongBao == JOptionPane.YES_OPTION) {
            this.dispose();
        }
    }//GEN-LAST:event_btDongActionPerformed

    private void btCapNhatCTTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCapNhatCTTActionPerformed
        this.capNhatChiTietThuoc();
    }//GEN-LAST:event_btCapNhatCTTActionPerformed

    private void btHuyDSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btHuyDSActionPerformed
        this.huyctt();
    }//GEN-LAST:event_btHuyDSActionPerformed

    private void btDongDSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDongDSActionPerformed
        int thongBao = JOptionPane.showConfirmDialog(null, "Bạn có muốn đóng cập nhật chi tiết Thuốc?", "Thông báo", JOptionPane.YES_NO_OPTION);
        if (thongBao == JOptionPane.YES_OPTION) {
            this.dispose();
        }
    }//GEN-LAST:event_btDongDSActionPerformed
    //bắt sự kiện khi chọn chuột vào thuộc tính khác ở mục chọn tên thuốc
    private void cbChonTenThuocItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbChonTenThuocItemStateChanged
        // TODO add your handling code here:
        if (evt.getStateChange() == ItemEvent.SELECTED) {
            txtTenThuoc.setText(cbChonTenThuoc.getSelectedItem().toString());
        }
    }//GEN-LAST:event_cbChonTenThuocItemStateChanged
    //bắt sự kiện bên cập nhật chi tiết thuốc
    private void cbTenThuocItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbTenThuocItemStateChanged
        // TODO add your handling code here:
        //Lấy mã loại thuốc
        if (evt.getStateChange() == ItemEvent.SELECTED) {
            Vector vThuoc = new Vector();
            try {
                vLay = Thuoc.xemChiTietThuoc();
            } catch (SQLException ex) {
                Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                vThuoc = Thuoc.xemThuoc();
            } catch (SQLException ex) {
                Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
            }
            for (int i = 0; i < vThuoc.size(); i++) {
                t1 = (Thuoc) vThuoc.get(i);
                if (cbTenThuoc.getSelectedItem().toString().equals(t1.getTenThuoc().toString())) {
                    t = (Thuoc) vLay.get(i);
                    txtGia.setText("" + t.getGia());
                    txtSoLuong.setText("" + t.getSoLuong());
                    txtNguonGoc.setText(t.getNguonGoc());
                    String handung = t.getHanDung();
                    cbNgay.setSelectedItem(handung.substring(0, 2).trim());
                    cbThang.setSelectedItem(handung.substring(3, 5));
                    txtNam.setText(handung.substring(6));
                    txtCongDung.setText(t.getCongDung());
                    txtHuongDanDung.setText(t.getHuongDanDung());

                    //Lấy tên đơn vị tính
                    DonViTinh tendvt = new DonViTinh();
                    Vector luuDVT, ma = new Vector();
                    try {
                        ma.addElement(t.getMaDonViTinh());
                        luuDVT = dvt.layTenDVT(ma);
                        tendvt = (DonViTinh) luuDVT.get(luuDVT.size() - 1);
                        cbTenDonViTinh.setSelectedItem(tendvt.getTenDonViTinh());
                    } catch (SQLException ex) {
                        Logger.getLogger(CapNhat.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    }//GEN-LAST:event_cbTenThuocItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CapNhat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CapNhat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CapNhat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CapNhat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CapNhat().setVisible(true);

            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCapNhat;
    private javax.swing.JButton btCapNhatCTT;
    private javax.swing.JButton btDong;
    private javax.swing.JButton btDongDS;
    private javax.swing.JButton btHuy;
    private javax.swing.JButton btHuyDS;
    private javax.swing.JComboBox cbChonTenThuoc;
    private javax.swing.JComboBox cbLoaiThuoc;
    private javax.swing.JComboBox cbNgay;
    private javax.swing.JComboBox cbNhaCungCap;
    private javax.swing.JComboBox cbTenDonViTinh;
    private javax.swing.JComboBox cbTenThuoc;
    private javax.swing.JComboBox cbThang;
    private com.toedter.calendar.JDateChooserBeanInfo jDateChooserBeanInfo1;
    private com.toedter.calendar.JDateChooserBeanInfo jDateChooserBeanInfo2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField txtCongDung;
    private javax.swing.JTextField txtGia;
    private javax.swing.JTextArea txtHuongDanDung;
    private javax.swing.JTextField txtNam;
    private javax.swing.JTextField txtNguonGoc;
    private javax.swing.JTextField txtSoLuong;
    private javax.swing.JTextField txtTenThuoc;
    // End of variables declaration//GEN-END:variables
}
